/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 23735
 * Date: 2022-11-03
 * Time: 23:08
 */
class Solution {
    public int findJudge(int n, int[][] trust) {
        int [] people=new int[n+1];//存储n个人并用下标对应
        for(int i=0;i<trust.length;i++){
            int left=trust[i][0];
            int right=trust[i][1];
            //小镇法官不会相信任何人
            people[left]=-1;
            //如果已经被淘汰,就没有必要再继续增加票数
            if(people[right]!=-1){
                people[right]+=1;
            }
        }

        for(int i=1;i<=n;i++){
            if(people[i]==n-1){
                return i;
            }
        }
        return -1;
    }
}
